package dynamicprogramming.最长递增子序列;

import java.util.Arrays;

public class Solution {
    public int lengthOfLIS(int[] nums) {
        int ans = 1;
        /**
         * 假设d[i]表示在i处比nums[i]小的数有多少个
         * d[i] = max(d[j]) + 1   0=< j < i  nums[j] < nums[i]
         */
        int[] d = new int[nums.length];
        Arrays.fill(d, 1);
        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    d[i] = Math.max(d[j] + 1, d[i]);
                    ans = Math.max(ans, d[i]);
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution().lengthOfLIS(new int[]{10, 9, 2, 5, 3, 7, 101, 18}));
    }
}
